<template>
  <div class="my">
    <div class="top">
      <div class="top1">
        <img
          v-if="userInfo.photo"
          class="right"
          :src="userInfo.photo"
          alt=""
          @click="$router.push('/Info')"
        />
        <img
          v-else
          @click="$router.push('/Info')"
          class="right"
          src="../../../assets/logo.png"
          alt=""
        />
        <div class="middle">
          <div class="name">{{ userInfo.name }}</div>
          <div class="approve">申请认证</div>
        </div>
        <div class="left">
          <div class="read1">
            <van-icon name="notes-o"></van-icon>
          </div>
          <div class="read2">
            <div class="read3">今日阅读</div>
            <div class="read4">{{ Math.abs(userInfo.like_count) }}分钟</div>
          </div>
        </div>
      </div>
      <ul class="top2">
        <li class="top2-item">
          <div class="num">{{ userInfo.art_count }}</div>
          <div class="txt">动态</div>
        </li>
        <li class="top2-item">
          <div class="num">{{ userInfo.follow_count }}</div>
          <div class="txt">关注</div>
        </li>
        <li class="top2-item">
          <div class="num">{{ userInfo.fans_count }}</div>
          <div class="txt">粉丝</div>
        </li>
      </ul>
    </div>
    <ul class="content">
      <li class="content-item" @click="$router.push('/myshoucang')">
        <van-icon class="item-num1" name="star-o"></van-icon>
        <span class="item-txt">收藏</span>
      </li>
      <li class="content-item" @click="$router.push('/myshoucang')">
        <van-icon class="item-num2" name="clock-o"></van-icon>
        <span class="item-txt">历史</span>
      </li>
      <li class="content-item">
        <van-icon class="item-num3" name="newspaper-o"></van-icon>
        <span class="item-txt">作品</span>
      </li>
    </ul>
    <div class="bottom">
      <van-cell title="消息通知" is-link></van-cell>
      <van-cell title="用户反馈" is-link></van-cell>
      <van-cell title="小智同学" is-link></van-cell>
    </div>
  </div>
</template>

<script>
import { localGet } from '@/utils/mylocal'
import { mapState, mapActions } from 'vuex'
export default {
  computed: {
    ...mapState({
      userInfo: state => state.userInfo
    })
  },
  methods: {
    ...mapActions(['setUserInfo'])
  },
  created () {
    /* 判断有没有token */
    const loginInfo = localGet('token')
    if (!loginInfo || !loginInfo.token) {
      /* 提示用户没有登录,跳转到登录页 */
      this.$toast('请您先登录!')
      this.$router.push('/login')
      return
    }
    /* 得到用户信息 */
    this.setUserInfo()
  }
}
</script>

<style lang="less" scoped>
.my {
  background-color: #f5f7f9;
  .top {
    background: url('../../../assets/bgimg.png');
    width: 375px;
    height: 200px;
    .top1 {
      display: flex;
      align-items: center;
      padding-left: 20px;
      padding-top: 40px;
      .right {
        width: 66px;
        height: 66px;
        border-radius: 50%;
        border: 2px solid #fff;
      }
      .middle {
        flex: 1;
        margin-left: 15px;
        .name {
          font-size: 15px;
          font-family: Microsoft YaHei Regular, Microsoft YaHei Regular-Regular;
          font-weight: 400;
          text-align: left;
          color: #ffffff;
          letter-spacing: 1px;
        }
        .approve {
          width: 58px;
          height: 16px;
          background: #ffffff;
          border-radius: 16px;
          font-size: 10px;
          font-family: Microsoft YaHei Bold, Microsoft YaHei Bold-Bold;
          font-weight: 700;
          text-align: left;
          color: #3296fa;
          letter-spacing: 1px;
          margin-top: 15px;
          text-align: center;
          line-height: 17px;
        }
      }
      .left {
        width: 94px;
        height: 40px;
        background: rgba(0, 0, 0, 0.2);
        // background: #000000;
        border-radius: 20px 0 0 20px;
        text-align: center;
        line-height: 16px;
        display: flex;
        justify-content: center;
        align-content: space-between;
        .read1 {
          font-size: 18px;
          color: #fff;
          margin-top: 10px;
          margin-right: 10px;
        }
        .read2 {
          margin-top: 5px;
          .read3 {
            font-size: 12px;
            font-family: Microsoft YaHei Regular,
              Microsoft YaHei Regular-Regular;
            font-weight: 400;
            text-align: left;
            color: #ffffff;
            letter-spacing: 1px;
          }
          .read4 {
            font-size: 12px;
            font-family: Microsoft YaHei Regular,
              Microsoft YaHei Regular-Regular;
            font-weight: 400;
            text-align: left;
            color: #ffffff;
            letter-spacing: 1px;
          }
        }
      }
    }
    .top2 {
      display: flex;
      justify-content: space-around;
      align-items: center;
      .top2-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        .num {
          font-size: 18px;
          font-family: Arial Regular, Arial Regular-Regular;
          font-weight: 400;
          text-align: left;
          color: #ffffff;
          letter-spacing: 1px;
          margin-top: 25px;
          // margin-left: 4px;
        }
        .txt {
          font-size: 12px;
          font-family: Microsoft YaHei Regular, Microsoft YaHei Regular-Regular;
          font-weight: 400;
          text-align: left;
          color: #ffffff;
          letter-spacing: 1px;
        }
      }
    }
  }
  .content {
    display: flex;
    justify-content: space-around;
    align-items: center;
    background-color: #fff;
    height: 72px;
    .content-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      margin-top: 15px;
      .item-num1 {
        font-size: 24px;
        color: #eb5253;
      }
      .item-num2 {
        font-size: 24px;
        color: #ff9d1d;
      }
      .item-num3 {
        font-size: 24px;
        color: #678eff;
      }
      .item-txt {
        font-size: 12px;
        font-family: Microsoft YaHei Regular, Microsoft YaHei Regular-Regular;
        font-weight: 400;
        text-align: left;
        color: #333333;
        letter-spacing: 1px;
        margin-top: 4px;
      }
    }
  }
  .bottom {
    margin-top: 10px;
  }
}
</style>
